package com.pet.controller.webUser;

import com.pet.dto.web.PetInformationDTO;
import com.pet.result.Result;
import com.pet.service.PetInformationService;
import com.pet.vo.web.PetInformationVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 宠物信息
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class PetInformationController {

    @Autowired
    private PetInformationService petInformationService;


    /**
     * 添加宠物信息
     * @param petInformationDTO
     * @return
     */
    @PostMapping("/petInformation")
    private Result insertPetInformation(@RequestBody PetInformationDTO petInformationDTO){
        petInformationService.insertPetInformation(petInformationDTO);
        return Result.success();
    }

    /**
     * 查询所有宠物信息
     * 用于页面展示宠物信息
     * @return
     */
    @GetMapping("/petInformationAll")
    private Result<List<PetInformationVO>> selectPetInformationAll(){
        return Result.success(petInformationService.selectPetInformationAll());
    }

    /**
     * 修改宠物信息
     */
    @PutMapping("/petInformation")
    private Result updatePetInformation(@RequestBody PetInformationDTO petInformationDTO){
        log.info("修改宠物信息");
        petInformationService.updatePetInformation(petInformationDTO);
        return Result.success();
    }

    /**
     * 删除宠物信息
     */
    @DeleteMapping("/petInformation")
    private Result deletePetInformation(@RequestParam Integer id){
        log.info("删除宠物信息：{}",id);
        petInformationService.deletePetInformation(id);

        return Result.success();
    }

    /**
     * 查询个人宠物信息
     */
    @GetMapping("/petSelfInformation")
    public Result<List<PetInformationVO>> selectPetSelfInformation(){
        log.info("查询个人宠物信息");

        return Result.success(petInformationService.selectPetSelfInformation());
    }

    /**
     * 根据用户id查询宠物信息
     */
    @GetMapping("/petInformationPersonal")
    public Result<List<PetInformationVO>> selectPetInformationPersonal(@RequestParam Integer userId){
        log.info("查询个人宠物信息:{}",userId);

        return Result.success(petInformationService.selectPetInformationPersonal(userId));
    }
}
